package com.sskj.givecoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.givecoin.m.HttpConfig;
import com.sskj.givecoin.m.bean.HttpData;
import com.sskj.givecoin.m.http.JsonCallBack;
import com.sskj.givecoin.p.base.BasePresenter;
import com.sskj.givecoin.utils.ToastUtil;
import com.sskj.givecoin.v.activity.BindMobileActivity;


public class BindMobileActivityPresenter extends BasePresenter<BindMobileActivity> {

    public void sendCode(String mobile) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("mobile", mobile)
                .params("type", 3)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getStatus() == 200) {
                            mView.sendCodeOk();
                        } else {
                            mView.sendCodeError();
                            ToastUtil.showShort(httpListData.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                    }
                });
    }

    public void bindMobile(String account, String mobile, String code) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_MOBILE)
                .params("account", account)
                .params("mobile", mobile)
                .params("code", code)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getStatus() == 200) {
                            mView.bingSuccess();
                        } else {
                            ToastUtil.showShort(httpListData.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                    }
                });
    }
}
